package com.runjian.rundo.iot.agent.iec104.parser.frame.control.system;

import com.runjian.rundo.iot.agent.iec104.parser.frame.ASDUFrame;
import com.runjian.rundo.iot.agent.iec104.parser.frame.InfoElement;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ByteUtil;
import lombok.Getter;
import lombok.Setter;

/**
 * C_RD_NA_2(0x84, "读多个参数命令(参数设置)"),
 *
 * @author CaoQingHua
 */
@Getter
@Setter
public class C_RD_NA_2 extends ASDUFrame {

    @Override
    public void analysisInfo(byte[] msg) {
        // 读多个参数命令(参数设置)
        for (int i = 0; i < this.getNumber(); i++) {
            this.addInfoElement(InfoElement.<Float>builder()
                .address(ByteUtil.bytesToInt(new byte[] {msg[12 + (7 * i)], msg[13 + (7 * i)], msg[14 + (7 * i)], 0x00}))
                .value(Float.intBitsToFloat(ByteUtil.bytesToInt(ArrayUtil.sub(msg, 15 + (7 * i), 19 + (7 * i))))).build());
        }
    }
}
